package com.example.demo.controller;

import com.example.demo.controller.data.ReturnData;
import com.example.demo.controller.vo.RegisterVo;
import com.example.demo.entity.Admin;
import com.example.demo.entity.User;
import com.example.demo.sevice.AdminService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 管理员接口控制类
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    AdminService adminService;

//    登录接口
    @PostMapping("login")
    public ReturnData login(@RequestBody Admin admin){
        return  adminService.login(admin.getUsername(),admin.getPasswprd());
    }

    /**
     * 分页获取用户列表接口
     * @param page
     * @param limit
     * @param nickname
     * @return
     */

    @GetMapping("/user/list")
    public ReturnData list(@RequestParam(defaultValue = "1")int page,
                           @RequestParam(defaultValue = "20")int limit,
                           @RequestParam(defaultValue = "") String nickname ) {
        return adminService.getUserList(page,limit,nickname);
    }

    /**
     * 删除用户的接口
     * @param user
     * @return
     */
    @PostMapping("/user/delete")
    public ReturnData deleteUser(@RequestBody User user){
        return adminService.deleteUser(user.getId());
    }

    @PostMapping("updateUserInfo")
    public ReturnData updateUserInfo(@RequestBody RegisterVo user){
        return adminService.updateUserInfo(user);
    }

    @PostMapping("/circle/list")
    public ReturnData getCircleList(@RequestParam(defaultValue = "1")int page,
                                    @RequestParam(defaultValue = "20") int pageSize){
        return adminService.getCircleList(page,pageSize);
    }

    /**
     * 评论列表接口 面向管理员的
     * @param page 页码
     * @param pageSize 每一页的长度 默认为10
     * @return
     */
    @PostMapping("/comment/list")
    public ReturnData getCommentList(@RequestParam(defaultValue = "1")int page,
                                     @RequestParam(defaultValue = "20") int pageSize,
                                     int circleId){
          return adminService.getCommentList(page,pageSize,circleId);
    }
}
